//import {ethers}  from "https://cdnjs.cloudflare.com/ajax/libs/ethers/5.7.2/ethers.min.js";
//require( "@ethersproject/shims");
const {ethers} = require('ethers');
const abifromFile = require('./sol/HelloWorld.abi.json');
//import { ethers } from 'ethers';

class HelloWorldContract {
  //abiStr =
  //  '[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"newname","type":"string"}],"name":"onset","type":"event"},{"inputs":[],"name":"get","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"n","type":"string"}],"name":"set","outputs":[],"stateMutability":"nonpayable","type":"function"}]';
  abiInterface = new ethers.utils.Interface(abifromFile);
  constructor() {
    //this.abiInterface = new ethers.utils.Interface(abifromFile);
  }
  create_set_data = function (data) {
    var funcdata_hex = this.abiInterface.encodeFunctionData('set', [data]);
    return funcdata_hex;
  };

  create_get() {
    console.log('create_get');
    var funcdata_hex = this.abiInterface.encodeFunctionData('get', []);
    return funcdata_hex;
  }
  //document.getElementById("test").innerHTML = funcdata_hex;
}

module.exports.HelloWorldContract = HelloWorldContract;
